import instance from "@/http/index.js"
import { method } from "lodash"

// 发布消息 前端参数: 消息题目 消息分类 消息部门 消息发布者 消息接受者 消息内容 消息等级
export const publishMessageAPI = (data) => {
  const {
    message_title,
    ...message_level
  } = data
  return instance({
    url: "/msg/publishMessage",
    method: "post",
    data: {
      message_title,
      ...message_level
    }
  })
}

// 获取公司公告列表 参数: 无
export const getCompanyMessageListAPI = () => {
  return instance({
    url: "/msg/getCompanyMessageList",
    method: "get"
  })
}

// 获取公司系统消息列表 参数: 无
export const getSystemMessageListAPI = () => {
  return instance({
    url: "/msg/getSystemMessageList",
    method: "get"
  })
}

// 编辑公告
export const editMessageAPI = (data) => {
  const {
    message_title,
    message_publish_department,
    message_content,
    message_publish_name,
    message_receipt_object,
    message_level,
    id
  } = data
  return instance({
    url: "/msg/editMessage",
    method: "post",
    data: {
      message_title,
      message_publish_department,
      message_content,
      message_publish_name,
      message_receipt_object,
      message_level,
      id
    }
  })
}

// 根据发布部门获取消息 参数: 发布部门
export const getMessageByDepartmentAPI = (data) => {
  const { message_publish_department, pager } = data
  return instance({
    url: "/msg/getMessageByDepartment",
    method: "post",
    data: {
      message_publish_department,
      pager
    }
  })
}

// 根据部门获取消息总数
export const getMessageCountByDepartmentAPI = (data) => {
  const { message_publish_department } = data
  return instance({
    url: "/msg/getMessageCountByDepartment",
    method: "post",
    data: {
      message_publish_department
    }
  })
}

// 根据等级获取消息 参数: 等级
export const getMessageByLevelAPI = (data) => {
  const { message_level, pager } = data
  return instance({
    url: "/msg/getMessageByLevel",
    method: "post",
    data: {
      message_level,
      pager
    }
  })
}

// 根据等级获取消息总数
export const getMessageCountByLevelAPI = (data) => {
  const { message_level } = data
  return instance({
    url: "/msg/getMessageCountByLevel",
    method: "post",
    data: {
      message_level
    }
  })
}

// 根据 id 获取消息 参数: id
export const getMessageByIdAPI = (data) => {
  const { id } = data
  return instance({
    url: "/msg/getMessageById",
    method: "post",
    data: {
      id
    }
  })
}

// 更新点击量 参数: id, message_click_number
export const updateClickNumAPI = (data) => {
  const { id, message_click_number } = data
  return instance({
    url: "/msg/updateClickNum",
    method: "post",
    data: {
      id,
      message_click_number
    }
  })
}

// 初次删除 参数: id
export const deleteMessageFirstAPI = (data) => {
  const { id } = data
  return instance({
    url: "/msg/deleteMessageFirst",
    method: "post",
    data: {
      id
    }
  })
}

// 获取回收站列表 参数：无
export const getRecycleBinListAPI = () => {
  return instance({
    url: "/msg/getRecycleBinList",
    method: "get"
  })
}

// 获取回收站总数 参数：无
export const getRecycleBinTotalAPI = () => {
  return instance({
    url: "/msg/getRecycleBinTotal",
    method: "get"
  })
}

// 回收站换页 参数：pager
export const getRecycleBinByPagerAPI = (data) => {
  const { pager } = data
  return instance({
    url: "/msg/getRecycleBinByPager",
    method: "post",
    data: {
      pager
    }
  })
}

// 还原 参数：id
export const restoreMessageAPI = (data) => {
  const { id } = data
  return instance({
    url: "/msg/restoreMessage",
    method: "post",
    data: {
      id
    }
  })
}

// 彻底删除 参数：id
export const deleteMessageAPI = (data) => {
  const { id } = data
  return instance({
    url: "/msg/deleteMessage",
    method: "post",
    data: {
      id
    }
  })
}

// 获取公司公告总数 参数: 无
export const getCompanyMessageTotalAPI = () => {
  return instance({
    url: "/msg/getCompanyMessageTotal",
    method: "get"
  })
}

// 获取系统消息总数 参数: 无
export const getSystemMessageTotalAPI = () => {
  return instance({
    url: "/msg/getSystemMessageTotal",
    method: "get"
  })
}

// 公司公告列表换页 参数: pager
export const getCompanyMessageByPagerAPI = (data) => {
  const { pager } = data
  return instance({
    url: "/msg/getCompanyMessageByPager",
    method: "post",
    data: {
      pager
    }
  })
}

// 系统消息列表换页 参数: pager
export const getSystemMessageByPagerAPI = (data) => {
  const { pager } = data
  return instance({
    url: "/msg/getSystemMessageByPager",
    method: "post",
    data: {
      pager
    }
  })
}